import json

from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt

from app01.models import Users, Response


# Create your views here.
def index(request):
    return HttpResponse("欢迎使用");
@csrf_exempt
def login(request):
    print("============================================login")
    print(request)
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        # try:
        print(Users().fetch_exist(username,password))
        print(type(Users().fetch_exist(username,password)))
        result = Users().fetch_exist(username, password)
        print(type(result))
        print(len(result))
        if len(result)!=0:
            return Response().response(1)
        else:
            return Response().response(0)